home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj0487.arc / FASTBLK.ASM < prev    next >
Assembly Source File  |  1987-02-20  |  2KB  |  51 lines

  1. ; Fast (32-bit) block move for 80386 computers. 
  2. ; Calling program selects 16- or a 32-bit move.
  3. ; Calling program must be sure 80386 is present for 32-bit move.
  4. ; For best performance, source and destination blocks should begin on
  5. ;  doubleword (for 32-bit move) or word (for 16-bit move) boundary. 
  6. ; Automatically handles block sizes with odd words and bytes. 
  7. ; Input: DS:SI = source.
  8. ;     ES:DI = destination.
  9. ;     CX    = number of bytes to move.
  10. ;     AL    = 1 to perform fast 32-bit move (for 80386 only),
  11. ;         0 to perform standard 16-bit move (for 8088/86/286).
  12. ; Results:
  13. ;  CX & BX destroyed, SI points to the byte after the end of the 
  14. ;  source block, DI points to the byte after the end of the 
  15. ;  destination block, direction flag cleared.
  16. ;
  17. cseg    segment    word public 'CODE'
  18.     assume    cs:cseg
  19.     public    FastBlockMove
  20. FastBlockMove    proc    near
  21.     cld
  22.     xor    bx,bx    ;clear odd-size flags
  23.     shr    cx,1    ;convert move size to words
  24.     jnc    CheckFor32BitMove
  25.     mov    bl,1    ;indicate odd byte 
  26. CheckFor32BitMove:
  27.     and    al,al    ;has caller requested a 32-bit move?
  28.     jz    DoBlockMove
  29.     shr    cx,1    ;32-bit move -- convert to dbl words
  30.     jnc    Do32BitMove
  31.     mov    bh,1    ;indicate odd word
  32. Do32BitMove:
  33.     db    66h    ;prefix to make the default size for the
  34.             ; following instruction 32 bits.
  35. DoBlockMove:
  36.     rep    movsw        ;move the block -- the move normally defaults
  37.             ; to 16 bits at a time, but if the size
  38.             ; prefix was executed, 32 bits will be
  39.             ; moved on each iteration
  40.     and    bh,bh    ;is there an odd word?
  41.     jz    TestOddByte
  42.     movsw        ;if so, move it
  43. TestOddByte:
  44.     and    bl,bl    ;is there an odd byte?
  45.     jz    Exit
  46.     movsb        ;if so, move it
  47. Exit:    ret
  48. FastBlockMove    endp
  49. cseg    ends
  50.     end
  51.